package cn.hycat;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lzhycat
 * @date 2022-09-07 01:56
 */
public class SB {
    public static void main(String[] args) {
        int[] ans = new int[10011];
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int h = sc.nextInt();
        for(int i = 0; i < (n - 1) * 2; i++) {
            int o = sc.nextInt();
            int t = sc.nextInt();
            runMain(o, t, h, ans);
        }
        int d = sc.nextInt();
        runDelete(d, ans);
    }

    private static void runMain(int o, int t, int h, int[] ans) {
        if(t == h && ans.length == 0) {
            ans[0] = t;
        }

        for(int i = 0; i < ans.length; i++) {
            if(ans[i] == t) {
                for(int j = i + 2; j < ans.length + 2; j++) {
                    ans[j] = ans[j-1];
                }
                ans[i + 1] = o;
                break;
            }
        }
    }

    private static void runDelete(int d, int[] ans) {
        ArrayList<Integer> list = new ArrayList(Collections.singleton(ans));
        List<Integer> collect = list.stream().filter((obj) -> obj != d).collect(Collectors.toList());

        for(int i = 0; i < collect.size(); i++) {
            System.out.print(collect.get(i) + " ");
        }
    }


}
